<?php

class Sherpa_Model_BasketProduct extends WSB_Model
{

	/**
	 * @var array
	 */
	protected $_data = array(
		// sherpa_productToBasket
		'productId' => null,
		'basketId' => null,
		'quantity' => null,
		'price' => null,
		'currencyCode' => null,
		'modified' => null,
		'created' => null,
		// sherpa_products
		'productId' => null,
		'parentProductId' => null,
		'articleNumber' => null,
		'productName' => null,
		'productLine' => null,
		'colorApplicationId' => null,
		// sherpa_sizes
		'size' => null,
		'colorApplication' => array(),
		'image' => array(),
		'imageVariant' => array()
	);

	/**
	 * @return string
	 */
	public function getImageFilename()
	{
		if(!empty($this->_data['imageVariant']['fileName'])) {
			return $this->_data['imageVariant']['fileName'];
		}
		if(!empty($this->_data['image']['fileName'])) {
			return $this->_data['image']['fileName'];
		}
		return '';
	}

	/**
	 * @return Sherpa_Model_ColorApplication
	 */
	public function getColorApplication()
	{
		return new Sherpa_Model_ColorApplication($this->_data['colorApplication']);
	}

	/**
	 * @return float
	 */
	public function getPriceTotal()
	{
		return $this->getQuantity() * $this->price;
	}

	/**
	 * @return array
	 */
	public function getQuantityRange()
	{
		$range = array();
		foreach(range(1, max($this->getQuantity(), 9)) AS $number) {
			$range[$number] = $number;
		}
		return $range;
	}

	/**
	 * Zusammengesetzter Produktname aus ProductName und ProductLine
	 *
	 * @return string
	 */
	public function getFullProductName()
	{
		return trim($this->_data['productName'] . ' ' . $this->_data['productLine']);
	}

}
